package org.jsemantic.servicerules.examples.energy;


import java.math.BigDecimal;
import java.util.Map;
import java.util.WeakHashMap;

import org.jsemantic.servicerules.examples.energy.services.InvoiceService;
import org.jservicerules.support.spring.SpringContextFactory;
import org.springframework.context.ApplicationContext;

public class InvoiceServiceFactory {

	private static String semanticServicesContext = "org/jsemantic/support/examples/energy/semantic-services.xml";

	private static ApplicationContext ctx = SpringContextFactory
	.getClassPathApplicationContexFactory(semanticServicesContext);
	private InvoiceServiceFactory() {
	}

	public static InvoiceService getInstance() {
		InvoiceService service =  (InvoiceService)ctx.getBean("invoiceService");
		service.setSessionVariables(getSessionVariables());
		return service;
	}
	
	private static Map getSessionVariables() {
		Map variables = new WeakHashMap();
		variables.put("kwh", new BigDecimal(0.091939));
		variables.put("ppower", new BigDecimal(1.618345));
		variables.put("months", new Integer(2));
		return variables;
	}
	

}
